/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	/// 
	/// module : levelLogic
	/// </summary>
	public class LevelHeroPOD : IPOD 
    {
        public readonly static Func<LevelHeroPOD> FACTORY = () => new LevelHeroPOD();
		public static Func<LevelHeroPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        /// 
        /// </summary>
		public long id;
		/// <summary>
        /// hero表的id
        /// </summary>
		public int cid;
		/// <summary>
        /// 皮肤id，entityId可以从其对应的配置里获取
        /// </summary>
		public int skinCid;
		/// <summary>
        /// 突破等级
        /// </summary>
		public int awakenLv;
		/// <summary>
        /// 等级
        /// </summary>
		public int level;
		/// <summary>
        /// 
        /// </summary>
		public int exp;
		/// <summary>
        /// 星级
        /// </summary>
		public int star;
		/// <summary>
        /// buff
        /// </summary>
        private List<LevelBuffPOD> m_buffs;
		/// <summary>
        /// 当前血量
        /// </summary>
		public int hp;
		/// <summary>
        /// 当前蓝量
        /// </summary>
		public int sp;
		/// <summary>
        /// 最大血量
        /// </summary>
		public int maxHp;
		/// <summary>
        /// 最大sp
        /// </summary>
		public int maxSp;
		
		
        public List<LevelBuffPOD> buffs
        {
            get
            {
                if(m_buffs == null)
                {
                    m_buffs = new();
                }
                return m_buffs;
            }
            private set => m_buffs = value;
        }
        public List<LevelBuffPOD> unsafe_buffs
        {
        	get => m_buffs;
        	set => m_buffs = value;
        }
		
		/*-- constructors --*/
		public LevelHeroPOD() {}
		public LevelHeroPOD(long id, int cid, int skinCid, int awakenLv, int level, int exp, int star, List<LevelBuffPOD> buffs, int hp, int sp, int maxHp, int maxSp) {
			this.id = id;
			this.cid = cid;
			this.skinCid = skinCid;
			this.awakenLv = awakenLv;
			this.level = level;
			this.exp = exp;
			this.star = star;
			this.m_buffs = buffs;
			this.hp = hp;
			this.sp = sp;
			this.maxHp = maxHp;
			this.maxSp = maxSp;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_long(id);
            _out.Write_int(cid);
            _out.Write_int(skinCid);
            _out.Write_int(awakenLv);
            _out.Write_int(level);
            _out.Write_int(exp);
            _out.Write_int(star);
            _out.Write_list_pod(m_buffs);
            _out.Write_int(hp);
            _out.Write_int(sp);
            _out.Write_int(maxHp);
            _out.Write_int(maxSp);
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            id = _in.Read_long();
            if(!_in.HasRemaining()) return;
            cid = _in.Read_int();
            if(!_in.HasRemaining()) return;
            skinCid = _in.Read_int();
            if(!_in.HasRemaining()) return;
            awakenLv = _in.Read_int();
            if(!_in.HasRemaining()) return;
            level = _in.Read_int();
            if(!_in.HasRemaining()) return;
            exp = _in.Read_int();
            if(!_in.HasRemaining()) return;
            star = _in.Read_int();
            if(!_in.HasRemaining()) return;
            m_buffs = _in.Read_list_pod<LevelBuffPOD>(LevelBuffPOD.DynamicFactory);
            if(!_in.HasRemaining()) return;
            hp = _in.Read_int();
            if(!_in.HasRemaining()) return;
            sp = _in.Read_int();
            if(!_in.HasRemaining()) return;
            maxHp = _in.Read_int();
            if(!_in.HasRemaining()) return;
            maxSp = _in.Read_int();
        }
		
		public LevelHeroPOD Clone() {
            LevelHeroPOD o = DynamicFactory();
            o.id = id;
            o.cid = cid;
            o.skinCid = skinCid;
            o.awakenLv = awakenLv;
            o.level = level;
            o.exp = exp;
            o.star = star;
            if (m_buffs != null) {
                o.m_buffs = m_buffs.ConvertAll(o => o?.Clone());
            }
            o.hp = hp;
            o.sp = sp;
            o.maxHp = maxHp;
            o.maxSp = maxSp;
            return o;
        }
        
        public void Clear() {
            id = default;
            cid = default;
            skinCid = default;
            awakenLv = default;
            level = default;
            exp = default;
            star = default;
            m_buffs = default;
            hp = default;
            sp = default;
            maxHp = default;
            maxSp = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "LevelHeroPOD [";
			str += "id=";
			str += id;
			str += ", cid=";
			str += cid;
			str += ", skinCid=";
			str += skinCid;
			str += ", awakenLv=";
			str += awakenLv;
			str += ", level=";
			str += level;
			str += ", exp=";
			str += exp;
			str += ", star=";
			str += star;
			str += ", buffs=";
			str += m_buffs.ToString<LevelBuffPOD>();
			str += ", hp=";
			str += hp;
			str += ", sp=";
			str += sp;
			str += ", maxHp=";
			str += maxHp;
			str += ", maxSp=";
			str += maxSp;
			str += "]";
			return str;
		}
		
	}
}